package com.cea.papyrus.diagram.sequence.ui.dialogs;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

public class ChooseDurationEvent extends ApplicationWindow{
	public static  int START= 0;
	public static int END=1;
	public static int CANCEL=2;
	private final ArrayList<Button> buttonList;
	private String motivation = "";
	private Button buttonOk;
	private Button buttonCancel;
	private boolean applyDerivation = true;
	private int selection = 0;

	public ChooseDurationEvent() {
		super(null);
		buttonList = new ArrayList<Button>();

	}

	public boolean applyDerivation() {
		return applyDerivation;
	}

	protected void buttomComposite(org.eclipse.swt.widgets.Composite parent) {
		final Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new org.eclipse.swt.layout.GridLayout(2, false));
		buttonOk = new Button(composite, SWT.PUSH);
		buttonCancel = new Button(composite, SWT.PUSH);
		buttonOk.setText("Ok");
		buttonCancel.setText("cancel");
		buttonOk.addMouseListener(new MouseListener() {
			public void mouseDoubleClick(MouseEvent e) {
			}

			public void mouseDown(MouseEvent e) {
			}

			public void mouseUp(MouseEvent e) {
				final Iterator<Button> iterButton = buttonList.iterator();
				while (iterButton.hasNext()) {
					final Button currentButton = iterButton.next();
					if (currentButton.getSelection() == true) {
						selection = buttonList.indexOf(currentButton);
					}
				}
				close();
			}
		});
		buttonCancel.addMouseListener(new MouseListener() {
			public void mouseDoubleClick(MouseEvent e) {
			}

			public void mouseDown(MouseEvent e) {
			}

			public void mouseUp(MouseEvent e) {
				selection=CANCEL;
				close();
			}
		});

	}

	@Override
	public boolean close() {
		return super.close();
	}

	@Override
	protected Control createContents(Composite parent) {
		final FontRegistry fr = new FontRegistry();
		// set Title of the Window
		getShell().setText("Duration Event");
		final Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new org.eclipse.swt.layout.GridLayout(1, false));

		final Label label = new Label(composite, 1);
		label.setText("What kind of date do you want to set up?");
		
		final Button b = new Button(composite, SWT.RADIO);
		b.setText("Beginning of the duration");
		buttonList.add(b);
		final Button c = new Button(composite, SWT.RADIO);
		c.setText("End of the duration");
		buttonList.add(c);

		// Label criter= new Label(composite,1);
		// criter.setText(criteria);
		buttomComposite(composite);
		return composite;
	}

	public int getSelection() {
		return selection;
	}

	@Override
	public int open() {

		this.setBlockOnOpen(true);
		final int result = super.open();

		return result;
	}

	
}